﻿using System;
using System.Collections.Generic;
using System.Text;
using Algoritmia.DataStructures.Maps;
using Algoritmia.Utils;

namespace Algoritmia.DataStructures.Digraphs
{

    public class HashSetAdjacencyDigraph<T> : AdjacencyDigraph<T>
    {
        public HashSetAdjacencyDigraph(IEnumerable<T> vertices = null, IEnumerable<Tuple<T, T>> edges = null,
                                  bool directed = true, EqualityComparison<T> equalityComparison = null,
                                 Func<IEnumerable<T>, IMap<T, Sets.ISet<T>>> createMap = null,
                                 Func<IMap<T, Sets.ISet<T>>, T, IMap<T, Sets.ISet<T>>> redimensionMap = null)
            : base(vertices, edges, directed, equalityComparison, createMap, items => new Sets.HashSet<T>(), redimensionMap, (set,a) => set)
        {
        }
        public HashSetAdjacencyDigraph( IEnumerable<KeyValuePair<T, IEnumerable<T>>> edges = null,
                                  bool directed = true, EqualityComparison<T> equalityComparison = null,
                                 Func<IEnumerable<T>, IMap<T, Sets.ISet<T>>> createMap = null,
                                 Func<IMap<T, Sets.ISet<T>>, T, IMap<T, Sets.ISet<T>>> redimensionMap = null)
            : base(edges, directed, equalityComparison, createMap, items => new Sets.HashSet<T>(), redimensionMap, (set, a) => set)
        {
        }

        public override string ToString()
        {
            var sb = new StringBuilder(String.Format("{0} <{1}> [ ", GetType().Name, typeof(T).Name));

            foreach (var kv in _succs)
            {
                sb.Append(String.Format("( {0} , {1} ) ,", kv.Key, kv.Value));
            }
            sb.Append("]");
            return sb.ToString();
        }
    }
}
